//
//  ComposeViewController.m
//  SinaWebo
//
//  Created by wwj on 16/1/11.
//  Copyright © 2016年 亦心. All rights reserved.
//

#import "ComposeViewController.h"
#import "ComposeIdeaViewController.h"
#import "ComposeBaseViewController.h"
#import "NavigationController.h"
#import "SendStatusService.h"
#import "ComposeShareView.h"
#import "ComposeTopView.h"
#import "ComButtomView.h"


@interface ComposeViewController ()<ComposeShareViewDelegate>
@property (weak, nonatomic) UIVisualEffectView *effectView;
@property (weak, nonatomic) ComposeShareView *shareView;
@property (weak, nonatomic) ComposeTopView *topView;
@end

@implementation ComposeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBarHidden = TRUE;
    self.view.backgroundColor = [UIColor clearColor];
    
    //添加毛玻璃
    [self addBlurEffect];
    
    //添加顶部天气和广告
    [self addTopView];
    
    //添加中间控件
    [self addCenterView];
    
    //添加底部控件
    [self addButtomView];
    
    //获取天气和广告图片
    [self getWeatherData];
}

#pragma mark 添加毛玻璃
- (void)addBlurEffect{
    UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
    UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect];
    effectView.frame = self.view.bounds;
    [self.view addSubview:effectView];
    _effectView = effectView;
}

#pragma mark 添加顶部天气和广告
- (void)addTopView{
    ComposeTopView *topView = [ComposeTopView composeTopView];
    topView.x = 0;
    topView.y = 44;
    [_effectView addSubview:topView];
    _topView = topView;
}

#pragma mark 添加中间控件
-(void)addCenterView{
    ComposeShareView *shareView = [ComposeShareView composeShareView];
    shareView.titleArray = @[@"文字", @"照片/视频", @"头条文章",
                             @"签到", @"点评", @"更多"];
    shareView.imgArray = @[@"tabbar_compose_idea", @"tabbar_compose_voice", @"tabbar_compose_headlines",
                           @"tabbar_compose_lbs",@"tabbar_compose_review", @"tabbar_compose_more"];
    shareView.frame = CGRectMake(0, 200, kScreenW, 0);
    shareView.delegate = self;
    [_effectView addSubview:shareView];
    _shareView = shareView;
}


#pragma mark 添加底部控件
-(void)addButtomView{
    ComButtomView *buttomView = [ComButtomView comButtomView];
    buttomView.frame = CGRectMake(0, kScreenH - 44, kScreenW, 0);
    [_effectView addSubview:buttomView];
    
    __weak typeof (self) weakSelf = self;
    __weak typeof (_shareView) weakShareView = _shareView;
    buttomView.onClickCancelBtn = ^{
        [weakSelf performSelector:@selector(dismView) withObject:nil afterDelay:0.3];
        [weakShareView hidden:nil];
        
    };
}

-(void)composeShareView:(ComposeShareView *)shareView clickBtnType:(ShareType)shareType{
    switch (shareType) {
        case ShareType_Idea://文字
            [self toViewControllerWithClassName:@"ComposeIdeaViewController"];
            break;
            
        case ShareType_Voice://照片,视频
            break;
            
        case ShareType_HeaderLins://头条文章
            break;
            
        case ShareType_Lbs://签到
            break;
         
        case ShareType_Review://点评
            break;
        case ShareType_More://更多
            break;
    }
}

-(void)toViewControllerWithClassName:(NSString *)className{
    ComposeBaseViewController *baseVC = [[NSClassFromString(className) alloc] init];
    NavigationController *naVC = [[NavigationController alloc] initWithRootViewController:baseVC];
    [DCURLRouter presentViewController:naVC animated:YES completion:nil];
}

-(void)dismView{
    [DCURLRouter dismissViewControllerAnimated:NO completion:nil];
}

#pragma mark 获取天气和广告图片
- (void)getWeatherData{
    WeatherRequest *request = [WeatherRequest request];
    request.lfid = @"100015551683910";
    request.luicode = @"10000001";
    request.featurecode = @"10000001";
    request.uicode = @"10000155";
    
    __weak typeof(self) weakSelf = self;
    [SendStatusService getWeatherDataWith:request success:^(WeatherResponse *response) {
        weakSelf.topView.model = response;
    } error:nil];
}

@end
